/*
 * sockets_Raid.c
 *
 *  Created on: 25/10/2011
 *      Author: utn_so
 */

#include <stdlib.h>
#include "raid.h"

#include "../Commons/sockets.h"
#include "structRaid.h"

#define RAID_PORT "3466"  // Puerto del Raid
#define SOCKET_RAID_MAX_BUFFER 10

int sockets_servidor(int argc, char **argv) {
	int addrlen = sizeof(struct sockaddr_in);
	char buffer [SOCKET_RAID_MAX_BUFFER];

	int descriptor= socket(AF_INET, SOCK_STREAM, 0);
	int remote_client;

	struct sockaddr_in *local_address = malloc(sizeof(struct sockaddr_in));
	struct sockaddr_in *remote_address=malloc(sizeof(struct sockaddr_in));

	{
		local_address ->sin_family = AF_INET;
		local_address ->sin_addr.s_addr = inet_addr("127.0.0.1");
		local_address ->sin_port = htons(RAID_PORT);

		bind(descriptor, (struct sockaddr *)local_address, sizeof(struct sockaddr_in));

	}

	listen(descriptor, 10);

	remote_client = accept(descriptor, (struct sockaddr *)remote_address, (void *) &addrlen);

	recv(remote_client, buffer,SOCKET_RAID_MAX_BUFFER, 0);
	//printf("%s", buffer);

	close(descriptor);

	return EXIT_SUCCESS;
}

